﻿module Sustainalytics.Common {

    export class AsyncHttpOperation<T>
    {
        private _promise: ng.IHttpPromise<T>;

        executing: boolean;


        constructor() {
        }


        execute(f: () => ng.IHttpPromise<T>): ng.IHttpPromise<T> {
            if (!f || this.executing === true) {
                return this._promise;
            }

            this.executing = true;
            this._promise = f();
            this._promise['finally'](() => this.executing = false);

            return this._promise;
        }
    }
}